﻿/**
 * FrameContainer
 *
 * @author		Allen Chou
 * @version		1.0.2 (last update: Jan 27 2008)
 * @link        http://cjcat.blogspot.com
 * @link		http://cjcat2266.deviantart.com
 */

package idv.cjcat.display.frame {
	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;
	
	import idv.cjcat.display.*;

	public class FrameContainer extends MovieClip {
		
		
		public var rect:Rectangle = new Rectangle(0, 0, 640, 400);
		public function FrameContainer() {
		}
		
		private var i:int;
		private var f:Frame;
		public function update(e:Event = null):void {
			if (stage == null) return;
			for (i = 0; i < numChildren; i++) {
				if ((f = (getChildAt(i) as Frame)) != null) {
					switch(f.frameMode) {
						case FrameMode.TOP:
							f.x = rect.x + rect.width / 2;
							f.y = rect.y;
							break;
						case FrameMode.BOTTOM:
							f.x = rect.x + rect.width / 2;
							f.y = rect.y + rect.height;
							break;
						case FrameMode.LEFT:
							f.x = rect.x;
							f.y = rect.y + rect.height / 2;
							break;
						case FrameMode.RIGHT:
							f.x = rect.x + rect.width;
							f.y = rect.y + rect.height / 2;
							break;
						case FrameMode.TOP_LEFT:
							f.x = rect.x;
							f.y = rect.y;
							break;
						case FrameMode.TOP_RIGHT:
							f.x = rect.x + rect.width;
							f.y = rect.y;
							break;
						case FrameMode.BOTTOM_LEFT:
							f.x = rect.x;
							f.y = rect.y + rect.height;
							break;
						case FrameMode.BOTTOM_RIGHT:
							f.x = rect.x + rect.width;
							f.y = rect.y + rect.height;
							break;
							
						case FrameMode.CENTER:
						default:
							f.x = rect.x + rect.width / 2;
							f.y = rect.y + rect.height / 2;
							trace(rect.x, rect.width);
							trace(f.x);
							break;
					}
				}
			}
		}
	}
}